package cqrtplm.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Data
public class FormDataDTO {
    private String key;
    private Object value;

    public FormDataDTO(String key, Object value) {
        this.key = key;
        this.value = value;
    }


    public static List<FormDataDTO> convertToFormDataDTO(JSONObject formData) {
        Set<String> keys = formData.keySet();
        List<FormDataDTO> dtoList = new ArrayList<>();

        for (String key : keys) {
            Object value = formData.get(key);
            dtoList.add(new FormDataDTO(key, value));
        }
        return dtoList;
    }
}
